package cn.yrec.rain.analysis.utils;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 描述:
 *  日期格式监测
 * @createDate: 2023/03/30 23:51
 * @author: yanglichen
 */
public class DateFormatTest {
    public static void main(String[] args) {
        String dateStr = "2023-01-01 00:10:10";
        Date date = DateUtil.parse(dateStr, DatePattern.NORM_DATETIME_PATTERN);
        testDateFormat(date, DatePattern.NORM_DATE_PATTERN);
        System.out.println(DateUtil.format(date, DatePattern.NORM_DATE_PATTERN));

    }

    private static Boolean testDateFormat(Date date, String format) {
        DateFormat formatter = new SimpleDateFormat(format);
        formatter.setLenient(false);
        try{
            formatter.format(date);
            System.out.println(date);
            System.out.print("格式正确！");
        }catch(Exception e){
            System.out.println("格式错误！");
        }
        return false;
    }
}
